﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace reseaux_neurones
{
    class Reseaux
    {

        Neurone[] neuronesCache;
        Neurone neuroneSortie;
        private double error;

        public Reseaux(int _nombreNeurone)
        {

            /* initialize neuronal */
            Run.NombreNeurones = _nombreNeurone;
            neuronesCache = new Neurone[_nombreNeurone];
            neuroneSortie = new Neurone();


            for (int n = 0; n < _nombreNeurone; n++)
            {
                neuronesCache[n] = new Neurone();
            }

        }


        public Neurone getHiddenNeuronal(int _i)
        {
            return this.neuronesCache[_i];
        }

        public Neurone[] getHiddenNeuronal()
        {
            return this.neuronesCache;
        }

        public Neurone getFinalNeuronal()
        {
            return this.neuroneSortie;
        }

        public void setError(double _err)
        {
            this.error = _err;
        }

        public double getError()
        {
            return this.error;
        }

        public void Sauvegarde()
        {

        }





        //   double[][] sorted = Utilitaire.Sort(error);



        /*  public double[][] Selection(double[][] _tab)
          {
              double[][] newPoids;// = new double[_tab.Length][_tab[0].length];

              for (int k = 0; k < _tab.Length; k++)
              {
                  System.Threading.Thread.Sleep(20);
                  Random rand = new Random();
                  double[][] parent = this.findParent();
                  if (rand.Next(1, 100) <= Reseaux.crossOver)
                  {
                      double[][] parent2 = this.findParent();
                      double[k][] = new Individu(parent, parent2);
                  }
                  else
                  {
                      newPop[k] = new Individu(parent, null);
                  }
              }


              this.individus = newPop;
              return this.individus;
          }

          private double[][] findParent()
          {
              Random rand = new Random();
              int random = rand.Next(1, 55);
              Individu parent = null;
              if (random > 0 && random <= 11)
              {
                  parent = this.individus[0];
              }
              else if (random > 11 && random <= 20)
              {
                  parent = this.individus[1];
              }
              else if (random > 20 && random <= 28)
              {
                  parent = this.individus[2];
              }
              else if (random > 28 && random <= 35)
              {
                  parent = this.individus[3];
              }
              else if (random > 35 && random <= 41)
              {
                  parent = this.individus[4];
              }
              else if (random > 41 && random <= 46)
              {
                  parent = this.individus[5];
              }
              else if (random > 46 && random <= 50)
              {
                  parent = this.individus[6];
              }
              else if (random > 50 && random <= 53)
              {
                  parent = this.individus[7];
              }
              else if (random > 53 && random <= 55)
              {
                  parent = this.individus[8];
              }
              else if (random > 55 && random <= 56)
              {
                  parent = this.individus[9];
              }
              return parent;
          }


          */
        //}

        public double MortOuVie(int _age, int _annee, int _ganglion)
        {
            /* TODO */
            /* Une fois l'apprentissage termniné, on fait les calculs */
            double sortie = Math.Round(neuroneSortie.getSortieFinal(), 0);



            return sortie;
        }

    }

}